package madixin.t647;

class Solution {


    public int countSubstrings(String s) {

        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            count = expandSubString(s, i, i, count);//奇数扩展
            count = expandSubString(s, i, i + 1, count);//偶数扩展
        }
        return count;
    }

    private int expandSubString(String s, int start, int end, int count) {
        while (start >= 0 && end < s.length() && s.charAt(start) == s.charAt(end)) {
            start--;
            end++;
            count++;
        }
        return count;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println("abc = " + s.countSubstrings("abc"));
        System.out.println("aaa = " + s.countSubstrings("aaa"));
    }
}
